Skip to content

chore: migrate users.getStatus endpoint to new OpenAPI pattern with AJV validation#39484

Open
Yashika-code wants to merge 6 commits intoRocketChat:developfrom
Yashika-code:chore/migrate-users-getStatus-openapi-clean
Open

chore: migrate users.getStatus endpoint to new OpenAPI pattern with AJV validation#39484
Yashika-code wants to merge 6 commits intoRocketChat:developfrom
Yashika-code:chore/migrate-users-getStatus-openapi-clean

Conversation

@Yashika-code
Copy link
Contributor

@Yashika-code Yashika-code commented Mar 9, 2026

Proposed changes

Migrates the users.getStatus REST API endpoint from the legacy API.v1.addRoute pattern to the new chained API.v1.get() pattern with AJV response schema validation and OpenAPI documentation support.

Closes #34983

Endpoints migrated

Endpoint Method Old Pattern New Pattern
users.getStatus GET addRoute.get() .get() chained

Architectural changes

  • Replaced legacy API.v1.addRoute('users.getStatus', ...) with the new chained .get('users.getStatus', ...) method
  • Added AJV response schema for 200 response with status, _id, and connectionStatus fields
  • Added 401: validateUnauthorizedErrorResponse for unauthorized access handling
  • Wired up ExtractRoutesFromAPI + declare module for automatic type inference
  • Removed manual /v1/users.getStatus typing from rest-typings (now inferred via module augmentation)

Files changed

  • apps/meteor/app/api/server/v1/users.ts — Main migration
  • packages/rest-typings/src/v1/users.ts — Removed old manual typing

Related project

This continues the REST API migration effort described in the GSoC 2026 project: Replace old REST API definitions over the new API.

cc @diego-sampaio @ggazzo

This PR is part of the ongoing REST API migration effort tracked in RocketChat/Rocket.Chat-Open-API#150

Summary by CodeRabbit

  • Refactor

    • Consolidated users.getStatus into a single, modernized GET route with stronger response validation.
    • When requesting your own status, responses may include both status and connectionStatus.
    • Endpoint requires authentication.
  • Documentation

    • OpenAPI documentation for users.getStatus updated.
  • Chores

    • Release entry and package patch updates included.

@Yashika-code Yashika-code requested review from a team as code owners March 9, 2026 18:44
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 9, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: dd0e51f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch
@rocket.chat/ui-client Patch
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/core-typings Patch
@rocket.chat/apps Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a46f7d88-40a8-4737-a9cd-a0794205f479

📥 Commits

Reviewing files that changed from the base of the PR and between f8b7afc and dd0e51f.

📒 Files selected for processing (1)
  • apps/meteor/app/api/server/v1/users.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/api/server/v1/users.ts

Walkthrough

Migrates users.getStatus from the legacy API.v1.addRoute form to the chained API.v1.get() pattern, adds AJV response validation and OpenAPI metadata, removes the old public typing, and adds a changeset bumping related package patch versions.

Changes

Cohort / File(s) Summary
Changeset Documentation
\.changeset/migrate-users-getStatus-openapi.md
Adds a changeset documenting migration of users.getStatus to the chained API pattern with AJV response validation and OpenAPI metadata; bumps @rocket.chat/meteor and @rocket.chat/rest-typings.
API Route Implementation
apps/meteor/app/api/server/v1/users.ts
Adds API.v1.get('users.getStatus', ...) GET route with authRequired: true, AJV-validated responses (401 and 200 with success, optional _id, status enum, optional connectionStatus, optional message); consolidates handler logic and removes the previous standalone API.v1.addRoute('users.getStatus', ...) block.
Type Definitions
packages/rest-typings/src/v1/users.ts
Removes the public '/v1/users.getStatus' endpoint signature from UsersEndpoints (deleted the GET method type returning status, optional message, optional _id, and optional connectionStatus).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  actor AuthService
  participant API_Server as API.v1.get('users.getStatus')
  participant Database as UsersDB

  Client->>API_Server: GET users.getStatus (auth token, params)
  API_Server->>AuthService: validate token
  AuthService-->>API_Server: auth OK / unauthorized
  alt authorized
    API_Server->>Database: fetch target user (or use requesting user)
    Database-->>API_Server: user record (status, connectionStatus, message, _id)
    API_Server-->>Client: 200 { success, _id?, status, connectionStatus?, message? }
  else unauthorized
    API_Server-->>Client: 401 { error }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: migrating the users.getStatus endpoint to a new OpenAPI pattern with AJV validation, which aligns with the actual code changes in the PR.
Linked Issues check ✅ Passed The PR successfully implements the OpenAPI migration objectives from #34983 by converting users.getStatus from legacy API.v1.addRoute to chained API.v1.get() with AJV response validation and removing manual type definitions.
Out of Scope Changes check ✅ Passed All changes are directly related to the users.getStatus endpoint migration and OpenAPI integration scope, with no unrelated modifications detected across the affected files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/app/api/server/v1/users.ts`:
- Line 22: The file imports validateForbiddenErrorResponse but still calls
validateBadRequestErrorResponse at runtime causing an undefined symbol; either
replace the call to validateBadRequestErrorResponse with
validateForbiddenErrorResponse where appropriate (e.g., at the call site around
the code that currently references validateBadRequestErrorResponse) or
re-add/import validateBadRequestErrorResponse if that validator is the intended
one, and remove the unused validateForbiddenErrorResponse import if you choose
to keep validateBadRequestErrorResponse; ensure the validator name in the import
list and the validator used in the function/body match
(validateForbiddenErrorResponse vs validateBadRequestErrorResponse).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 108ce93e-1353-4994-ac45-a98a08dc8339

📥 Commits

Reviewing files that changed from the base of the PR and between f5f2374 and f2e2d20.

📒 Files selected for processing (3)
  • .changeset/migrate-users-getStatus-openapi.md
  • apps/meteor/app/api/server/v1/users.ts
  • packages/rest-typings/src/v1/users.ts
💤 Files with no reviewable changes (1)
  • packages/rest-typings/src/v1/users.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/api/server/v1/users.ts
🧠 Learnings (9)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.

Applied to files:

  • .changeset/migrate-users-getStatus-openapi.md
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • .changeset/migrate-users-getStatus-openapi.md
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • .changeset/migrate-users-getStatus-openapi.md
📚 Learning: 2026-03-09T18:39:14.020Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:14.020Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.

Applied to files:

  • apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.

Applied to files:

  • apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/api/server/v1/users.ts
🔇 Additional comments (2)
apps/meteor/app/api/server/v1/users.ts (1)

882-922: LGTM - Route migration follows the expected pattern.

The new chained .get() pattern is correctly implemented with:

  • authRequired: true for authentication
  • Proper 401/200 response schemas
  • Handler logic that correctly differentiates between self-status requests (includes connectionStatus) and other-user requests

One minor observation: On line 907, Users.findOneById(this.userId) could theoretically return null, but since the request is authenticated, this is extremely unlikely. The optional chaining at lines 909-911 handles this gracefully.

.changeset/migrate-users-getStatus-openapi.md (1)

1-6: LGTM - Changeset correctly documents the migration.

The changeset accurately describes the endpoint migration and appropriately uses patch version bumps for both affected packages.

Comment on lines +888 to +892
200: ajv.compile<{
_id?: string;
status: 'online' | 'offline' | 'away' | 'busy';
connectionStatus?: 'online' | 'offline' | 'away' | 'busy';
}>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's the message props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out! I've added the message property to the response schema as an optional field to match the existing API response.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/app/api/server/v1/users.ts">

<violation number="1" location="apps/meteor/app/api/server/v1/users.ts:914">
P2: Potential AJV validation failure: `message` can be null/undefined but schema requires string type. When `statusText` is undefined or null, the response object will have `message: undefined` or `message: null`, which fails AJV's `type: 'string'` validation. This should normalize nullish values by conditionally including `message` only when it has a valid string value.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Yashika-code Yashika-code deleted the chore/migrate-users-getStatus-openapi-clean branch March 10, 2026 12:52
@Yashika-code Yashika-code restored the chore/migrate-users-getStatus-openapi-clean branch March 10, 2026 13:06
@Yashika-code Yashika-code reopened this Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants